import request from './request'

// 用户相关API
export const userApi = {
  // 登录
  login: (credentials) => request.post('/users/login/', credentials),
  
  // 注册
  register: (userData) => request.post('/users/register/', userData),
  
  // 登出
  logout: () => request.post('/users/logout/'),
  
  // 获取用户资料
  getProfile: () => request.get('/users/profile/'),
  
  // 更新用户资料
  updateProfile: (data) => request.put('/users/profile/', data),
  
  // 修改密码
  changePassword: (data) => request.post('/users/change_password/', data),
  
  // 获取用户列表
  getUsers: (params) => request.get('/users/', { params })
}

// 智能体相关API
export const agentApi = {
  // 获取智能体类型列表
  getAgentTypes: () => request.get('/agent-types/'),
  
  // 获取智能体列表
  getAgents: (params) => request.get('/agents/', { params }),
  
  // 获取我的智能体
  getMyAgents: (params) => request.get('/agents/my_agents/', { params }),
  
  // 获取推荐智能体
  getFeaturedAgents: (params) => request.get('/agents/featured/', { params }),
  
  // 创建智能体
  createAgent: (data) => request.post('/agents/', data),
  
  // 获取智能体详情
  getAgent: (id) => request.get(`/agents/${id}/`),
  
  // 更新智能体
  updateAgent: (id, data) => request.put(`/agents/${id}/`, data),
  
  // 删除智能体
  deleteAgent: (id) => request.delete(`/agents/${id}/`),
  
  // 与智能体对话
  chatWithAgent: (id, data) => request.post(`/agents/${id}/chat/`, data),
  
  // 评分智能体
  rateAgent: (id, data) => request.post(`/agents/${id}/rate/`, data),
  
  // 获取智能体评分
  getAgentRatings: (id, params) => request.get(`/agents/${id}/ratings/`, { params })
}

// 对话相关API
export const conversationApi = {
  // 获取对话列表
  getConversations: (params) => request.get('/conversations/', { params }),
  
  // 创建对话
  createConversation: (data) => request.post('/conversations/', data),
  
  // 获取对话详情
  getConversation: (id) => request.get(`/conversations/${id}/`),
  
  // 删除对话
  deleteConversation: (id) => request.delete(`/conversations/${id}/`),
  
  // 获取对话消息
  getMessages: (conversationId, params) => request.get(`/conversations/${conversationId}/messages/`, { params })
}

// 学习相关API
export const learningApi = {
  // 获取课程列表
  getCourses: (params) => request.get('/courses/', { params }),
  
  // 获取课程详情
  getCourse: (id) => request.get(`/courses/${id}/`),
  
  // 报名课程
  enrollCourse: (id) => request.post(`/courses/${id}/enroll/`),
  
  // 获取我的课程
  getMyCourses: (params) => request.get('/enrollments/', { params }),
  
  // 获取课程进度
  getCourseProgress: (courseId) => request.get(`/courses/${courseId}/progress/`),
  
  // 更新学习进度
  updateProgress: (lessonId, data) => request.post(`/lessons/${lessonId}/progress/`, data)
}

// 知识库相关API
export const knowledgeApi = {
  // 获取知识库列表
  getKnowledgeBases: (params) => request.get('/knowledge-bases/', { params }),
  
  // 创建知识库
  createKnowledgeBase: (data) => request.post('/knowledge-bases/', data),
  
  // 获取知识库详情
  getKnowledgeBase: (id) => request.get(`/knowledge-bases/${id}/`),
  
  // 更新知识库
  updateKnowledgeBase: (id, data) => request.put(`/knowledge-bases/${id}/`, data),
  
  // 删除知识库
  deleteKnowledgeBase: (id) => request.delete(`/knowledge-bases/${id}/`),
  
  // 获取文档列表
  getDocuments: (params) => request.get('/documents/', { params }),
  
  // 上传文档
  uploadDocument: (data) => request.post('/documents/', data, {
    headers: { 'Content-Type': 'multipart/form-data' }
  }),
  
  // 删除文档
  deleteDocument: (id) => request.delete(`/documents/${id}/`),
  
  // 搜索知识库
  searchKnowledge: (params) => request.get('/knowledge/search/', { params })
}